/**
 * 
 */
package andersonb.mock.managedbeans;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import andersonb.mock.model.Entity;

/**
 * @author andersonb
 * 
 */
@ManagedBean
@SessionScoped
public class SessionManagedBean {

	/**
	 * 
	 */
	private String text;

	/**
	 * 
	 */
	private List<Entity> list;

	/**
	 * 
	 */
	private final List<Entity> listSub;

	/**
	 * 
	 */
	public SessionManagedBean() {
		// list = createEntityList();
		listSub = createEntityList2();
	}

	/**
	 * @return
	 */
	public List<Entity> createEntityList() {

		final int size = 10;
		List<Entity> list = new ArrayList<Entity>(size);
		for (int i = 0; i < size; i++) {
			Entity e = new Entity();
			e.setName("Nome " + i + 1);
			e.setValue("Valor " + i + 1);
			list.add(e);
		}

		return list;
	}

	public List<Entity> createEntityList2() {

		final int size = 3;
		List<Entity> list = new ArrayList<Entity>(size);
		for (int i = 0; i < size; i++) {
			Entity e = new Entity();
			e.setName("Sub-Registro " + i + 1);
			e.setValue("Valor " + i + 1);
			list.add(e);
		}

		return list;
	}

	public void popularTabela() {
		if (list == null || list.isEmpty()) {
			list = createEntityList();
		} else {
			list.clear();
		}

	}

	/**
	 * @param msg
	 * @return
	 */
	public String createMessage(final String msg) {
		return "Mensagem: " + msg;
	}

	public String getText() {
		return text;
	}

	public void setText(final String text) {
		this.text = text;
	}

	public List<Entity> getList() {
		return list;
	}

	/**
	 * @return the listSub
	 */
	public List<Entity> getListSub() {
		return listSub;
	}

	/**
	 * @param list
	 *            the list to set
	 */
	public void setList(final List<Entity> list) {
		this.list = list;
	}

}
